package com.bjsc.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.bjsc.mapper.DataMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.bjsc.entity.model.BetRecord;
import com.bjsc.service.IDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author create by VIC.Huang
 * @date 2018/3/4
 */
@Service
public class DataServiceImpl implements IDataService {
    @Autowired
    private DataMapper dataMapper;

    @Override
    public Page<Map<Object, Object>> selectBetRecordPage(Page<Map<Object, Object>> page) {
        List<BetRecord> tempList = dataMapper.selectBetRecords(page);
        List<Map<Object, Object>> result = new ArrayList<>(tempList.size());
        ObjectMapper objectMapper = new ObjectMapper();
        for (BetRecord temp : tempList) {
            result.add(objectMapper.convertValue(temp, Map.class));
        }
        page.setRecords(result);
        return page;
    }

    @Override
    public Page<Map<Object, Object>> selectOpenRecordPage(Page<Map<Object, Object>> page) {
        page.setRecords(dataMapper.selectOpenRecords(page));
        return page;
    }
}
